//
//  KKBaseNaviBarView.swift
//  MVVMSwfit
//
//  Created by CarShare on 2018/12/5.
//  Copyright © 2018年 CarShare. All rights reserved.
//

import UIKit



class KKBaseNaviBarView: UIView {

    //纯代码专用  xib不会调用
    override init(frame: CGRect) {

        super.init(frame: frame)
        
        self.configUI()
    }
    //是使用xib/storyBoard 开发的入口
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
//        fatalError 使用xib开发会直接崩溃 禁止xib使用本类
        fatalError("init(coder:) has not been implemented")
    }
    
    let statusH = UIApplication.shared.statusBarFrame.height
    
    lazy var titleLab:UILabel = UILabel(frame: CGRect(x: 80, y: statusH, width: UIScreen.main.bounds.width - 80 * 2, height: 44))
    
    lazy var leftBtn:UIButton = UIButton(type: .custom)
    
}
//MARK: --- 设置基类导航条 UI
extension KKBaseNaviBarView{
    func configUI(){
        titleLab.textColor = .red
        titleLab.font = UIFont.systemFont(ofSize: 18)
        titleLab.textAlignment = .center
        self.addSubview(titleLab)
    }
    
    
}

//MARK: --- 设置返回按钮
extension KKBaseNaviBarView{
    public enum BaseNaviLeftBtnType : Int{
        
        case backWord
        case backImage
    }
    var leftType : KKBaseNaviBarView.BaseNaviLeftBtnType{
        get{
            let type = BaseNaviLeftBtnType.backWord
            return type
        }
        set{
            leftBtn.frame = CGRect(x: 15, y: UIApplication.shared.statusBarFrame.height, width: 40, height: 44)

            if newValue == .backImage {
                leftBtn.setImage(#imageLiteral(resourceName: "home"), for: .normal)
            }else{
                leftBtn.setTitleColor(.red, for: .normal)
                leftBtn.setTitle("返回", for: .normal)
            }
            self.addSubview(leftBtn)
        }
    }
}
